<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <!-- <el-form-item label="质量文件编号" prop="fileCode">
        <el-input v-model="queryParams.fileCode" placeholder="请输入质量文件编号" clearable />
      </el-form-item> -->
      <!-- <el-form-item label="质量文件名称" prop="fileName">
        <el-input v-model="queryParams.fileName" placeholder="请输入质量文件名称" clearable />
      </el-form-item> -->
      <el-form-item label="问题编号" prop="workNo">
        <el-input v-model="queryParams.workNo" placeholder="请输入问题编号" clearable />
      </el-form-item>
      <el-form-item label="拆分时间" prop="dateTime">
        <el-date-picker clearable v-model="queryParams.dateTime" type="daterange" value-format="yyyy-MM-dd"
          range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="原因分析" prop="questionAnalysis">
        <el-select v-model="queryParams.questionAnalysis" placeholder="请选择原因分析" clearable>
          <el-option v-for="dict in dict.type.list_quality_question_analysis" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="问题等级" prop="questionLevel">
        <el-select v-model="queryParams.questionLevel" placeholder="请选择问题等级" clearable>
          <el-option v-for="dict in dict.type.list_quality_level" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="整改人" prop="revisePeopleId">
        <el-select v-model="queryParams.revisePeopleId" placeholder="请选择整改人" clearable>
          <el-option v-for="item in revisePeopleOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="拆分问题状态" prop="dataStatus">
        <el-select v-model="queryParams.dataStatus" placeholder="请选择拆分问题状态" clearable>
          <el-option v-for="dict in dict.type.list_quality_data_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList(true)">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="commonButtons">
      <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['quality:qualityFileItem:add']">新增</el-button>
      <!-- <el-button type="primary" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList(true)"></right-toolbar>
    </div>
    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="质量文件编号" width="120" prop="fileCode" /> -->
      <el-table-column label="问题编号" width="120" prop="workNo" />
       <el-table-column label="问题整改状态" width="120" prop="dataStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.list_quality_data_status" :value="scope.row.dataStatus" />
        </template>
      </el-table-column>
      <el-table-column label="问题描述" width="120" prop="questionDesc" />
      <el-table-column label="数据来源" align="center" prop="dataSource">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.list_quality_data_source" :value="scope.row.dataSource" />
            </template>
          </el-table-column>
      <el-table-column label="责任区域" width="120" prop="dutyAreaName" />
       <el-table-column label="检查人" width="120" prop="checkPeopleName" />
      <el-table-column label="整改人" width="120" prop="revisePeopleName" />
      <el-table-column label="复杳人" width="120" prop="reviewUserName" />
      <el-table-column label="通知人" width="120" prop="notifierName" />
      <!-- <el-table-column label="原因分析" width="120" prop="questionAnalysis">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.list_quality_question_analysis" :value="scope.row.questionAnalysis" />
        </template>
      </el-table-column> -->
      <el-table-column label="问题等级" width="120" prop="questionLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.list_quality_level" :value="scope.row.questionLevel" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="质量文件名称" width="120" prop="fileName" /> -->
      <!-- <el-table-column label="发文单位" width="120" prop="fileCompanyName" /> -->
      <!-- <el-table-column label="发文单位类型" width="120" prop="fileType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.list_quality_file_type" :value="scope.row.fileType" />
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="文件上传时间" width="120" prop="fileUpTime" /> -->
     
     
      <!-- <el-table-column label="退回次数" width="120" prop="numOfReturns" />
      <el-table-column label="退回时间" width="120" prop="returnTime" /> -->
      <el-table-column label="整改完成时间" width="160" prop="reviewTime" />
      <el-table-column label="要求整改完成日期" width="140" prop="reviseTheDates" />
      <!-- <el-table-column label="拆分时间" width="120" prop="splitTime" /> -->
      
      <el-table-column fixed="right" label="操作" align="center" width="200" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleView(scope.row)" v-hasPermi="['quality:qualityFileItem:query']">查看</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)"
            v-if="scope.row.canDel != '2'" v-hasPermi="['quality:qualityFileItem:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-if="scope.row.canDel != '2'" v-hasPermi="['quality:qualityFileItem:remove']">删除</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleSync(scope.row)"
            v-if="scope.row.dataStatus == '2'" v-hasPermi="['quality:questions:add']">同步问题库</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <AddDialog :visible.sync="dialogVisible" v-if="dialogVisible" @refresh="getList(true)" :data="selectRow"
      :title="title" :operateType="operateType" :dicts="dict.type">
    </AddDialog>
    <SyncDialog :visible.sync="syncDialogVisible" v-if="syncDialogVisible" :data="selectRow" :dicts="dict.type">
    </SyncDialog>
  </div>
</template>
<script>
import refreshMixin from "@/common/refreshMixin"
import AddDialog from "./components/addDialog.vue"
import SyncDialog from "./components/syncDialog.vue"
import { getDataList, getRevisePeople, deletedData,getedData } from "./api"
export default {
  name: "QualityFileItem",
  dicts: ["list_quality_data_source", "list_quality_data_status", "list_quality_rectification_deadline_status",
    "list_quality_question_beyond", "list_quality_question_analysis", "list_quality_level",
    "list_quality_rework_or_not", "list_quality_publish_or_not", "list_quality_file_type","list_quality_question_source"],
  mixins: [refreshMixin],
  components: { AddDialog, SyncDialog },
  data() {
    return {
      loading: false,
      list: [],
      total: 0,
      showSearch: true,
      queryParams: {
        pageNum: 0,
        pageSize: 10,
        fileCode: null,
        fileName: null,
        workNo: null,
        dateTime: [],
        questionAnalysis: null,
        questionLevel: null,
        revisePeopleId: null,
        dataStatus: null,
      },
      revisePeopleOptions: [],
      title: "",
      dialogVisible: false,
      selectRow: {},
      operateType: 'view',
      ids: [],
      syncDialogVisible: false,
    }
  },
  methods: {
    async getList(flag) { // true时为页内刷新，不传为project更改刷新
      if (!flag) {
        const res1 = await getRevisePeople({ ...this.queryParams, projectId: this.projectId })
        this.revisePeopleOptions = res1.rows.map(item => ({ value: item.userId, label: item.nickName }))
        this.queryParams.revisePeopleId = null
      }
      this.loading = true;
      const splitTimeStart = this.queryParams.dateTime.length ? this.queryParams.dateTime[0] : null
      const splitTimeEnd = this.queryParams.dateTime.length ? this.queryParams.dateTime[1] : null
      const params = { ...this.queryParams, splitTimeStart, splitTimeEnd, dateTime: null, projectId: this.projectId }
      const res = await getDataList(params)
      this.list = res.rows
      this.total = res.total
      this.loading = false
    },
    // 表单重置
    reset() {
      this.form = {
        pageNum: 0,
        pageSize: 10,
        fileCode: null,
        fileName: null,
        workNo: null,
        dateTime: [],
        questionAnalysis: null,
        questionLevel: null,
        revisePeopleId: null,
        dataStatus: null,
      };
      this.resetForm("form");
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.getList(true);
    },
    handleView(row) {
      this.operateType = 'view'
      this.selectRow = { ...row }
      this.title = "质量问题台账";
      this.dialogVisible = true;
    },
    handleAdd() {
      this.operateType = 'add'
      this.selectRow = {};
      this.title = "新增质量问题台账";
      this.dialogVisible = true;
    },
    handleEdit(row) {
      this.operateType = 'edit'
      getedData(row.id).then((data) => {
        console.log(data);
      })
      this.selectRow = { ...row }
      this.title = "编辑质量问题台账";
      this.dialogVisible = true;
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
    },
    handleExport() {
      const splitTimeStart = this.queryParams.dateTime.length ? this.queryParams.dateTime[0] : null
      const splitTimeEnd = this.queryParams.dateTime.length ? this.queryParams.dateTime[1] : null
      const params = { ...this.queryParams, splitTimeStart, splitTimeEnd, dateTime: null, projectId: this.projectId }
      this.download('/quality/qualityFileItem/export', {
        ...params
      }, `attach_${new Date().getTime()}.xlsx`)
    },
    async handleDelete(row) {
      const res = await this.$confirm('是否确认删除编号为' + row.id + '的数据项？', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
      if (res == 'confirm') {
        const res1 = await deletedData(row.id);
        if (res1.code == 200) {
          this.getList(true);
          this.$message.success("删除成功")
        }
      }
    },
    handleSync(row) {
      this.selectRow = { ...row }
      this.syncDialogVisible = true;
    },
  }
}
</script>
<style lang="scss" scoped>
.commonButtons {
  margin-bottom: 10px;
}
</style>